package com.myx.dao.category;

import com.myx.pojo.Category;
import com.myx.util.JdbcUtil;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    private final JdbcUtil jdbcUtil=new JdbcUtil();
    @Override
    public List<Category> getCategoryList() {

        String sql="select * from news_category";
        Object[] params={};
        ResultSet resultSet=jdbcUtil.getObjectByParams(sql,params);
        List<Category> categoryList=new ArrayList<>();
        try {
            while (resultSet.next()){
                int id=resultSet.getInt("id");
                String name=resultSet.getString("name");
                Date createDate=resultSet.getDate("createDate");
                int createBy=resultSet.getInt("createBy");
                Date modifyDate=resultSet.getDate("modifyDate");
                int modifyBy=resultSet.getInt("modifyBy");

                Category category=new Category();
                category.setId(id);
                category.setName(name);
                category.setCreateDate(createDate);
                category.setCreateBy(createBy);
                category.setModifyDate(modifyDate);
                category.setModifyBy(modifyBy);
                categoryList.add(category);

            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            this.jdbcUtil.closeResource();
        }
        return categoryList;
    }
}
